package com.bootdo.blog.dao;

import com.bootdo.blog.domain.TruckDO;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2021-03-07 10:38:33
 */
@Mapper
public interface TruckMapper {

	@Select("select `truck_id`, `truck_name`, `truck_temp`, `truck_type`, `driver`, `telephone`, `truck_number`, `package_time`, `truck_start`, `truck_end`, `flag`, `operator_id`, `appearance_id` from tb_truck where truck_id = #{id}")
	TruckDO get(Integer truckId);
	
	@Select("<script>" +
	"select * from tb_truck " + 
			"<where>" + 
		  		  "<if test=\"truckId != null and truckId != ''\">"+ "and truck_id = #{truckId} " + "</if>" + 
		  		  "<if test=\"truckName != null and truckName != ''\">"+ "and truck_name = #{truckName} " + "</if>" + 
		  		  "<if test=\"truckTemp != null and truckTemp != ''\">"+ "and truck_temp = #{truckTemp} " + "</if>" + 
		  		  "<if test=\"truckType != null and truckType != ''\">"+ "and truck_type = #{truckType} " + "</if>" + 
		  		  "<if test=\"driver != null and driver != ''\">"+ "and driver = #{driver} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  		  "<if test=\"truckNumber != null and truckNumber != ''\">"+ "and truck_number = #{truckNumber} " + "</if>" + 
		  		  "<if test=\"packageTime != null and packageTime != ''\">"+ "and package_time = #{packageTime} " + "</if>" + 
		  		  "<if test=\"truckStart != null and truckStart != ''\">"+ "and truck_start = #{truckStart} " + "</if>" + 
		  		  "<if test=\"truckEnd != null and truckEnd != ''\">"+ "and truck_end = #{truckEnd} " + "</if>" + 
		  		  "<if test=\"flag != null and flag != ''\">"+ "and flag = #{flag} " + "</if>" + 
		  		  "<if test=\"operatorId != null and operatorId != ''\">"+ "and operator_id = #{operatorId} " + "</if>" + 
		  		  "<if test=\"appearanceId != null and appearanceId != ''\">"+ "and appearance_id = #{appearanceId} " + "</if>" + 
		  			"</where>"+ 
			" <choose>" + 
	            "<when test=\"sort != null and sort.trim() != ''\">" + 
	                "order by ${sort} ${order}" + 
	            "</when>" + 
				"<otherwise>" + 
	                "order by truck_id desc" + 
				"</otherwise>" + 
	        "</choose>"+
			"<if test=\"offset != null and limit != null\">"+
			"limit #{offset}, #{limit}" + 
			"</if>"+
			"</script>")
	List<TruckDO> list(Map<String, Object> map);
	
	@Select("<script>" +
	"select count(*) from tb_truck " + 
			"<where>" + 
		  		  "<if test=\"truckId != null and truckId != ''\">"+ "and truck_id = #{truckId} " + "</if>" + 
		  		  "<if test=\"truckName != null and truckName != ''\">"+ "and truck_name = #{truckName} " + "</if>" + 
		  		  "<if test=\"truckTemp != null and truckTemp != ''\">"+ "and truck_temp = #{truckTemp} " + "</if>" + 
		  		  "<if test=\"truckType != null and truckType != ''\">"+ "and truck_type = #{truckType} " + "</if>" + 
		  		  "<if test=\"driver != null and driver != ''\">"+ "and driver = #{driver} " + "</if>" + 
		  		  "<if test=\"telephone != null and telephone != ''\">"+ "and telephone = #{telephone} " + "</if>" + 
		  		  "<if test=\"truckNumber != null and truckNumber != ''\">"+ "and truck_number = #{truckNumber} " + "</if>" + 
		  		  "<if test=\"packageTime != null and packageTime != ''\">"+ "and package_time = #{packageTime} " + "</if>" + 
		  		  "<if test=\"truckStart != null and truckStart != ''\">"+ "and truck_start = #{truckStart} " + "</if>" + 
		  		  "<if test=\"truckEnd != null and truckEnd != ''\">"+ "and truck_end = #{truckEnd} " + "</if>" + 
		  		  "<if test=\"flag != null and flag != ''\">"+ "and flag = #{flag} " + "</if>" + 
		  		  "<if test=\"operatorId != null and operatorId != ''\">"+ "and operator_id = #{operatorId} " + "</if>" + 
		  		  "<if test=\"appearanceId != null and appearanceId != ''\">"+ "and appearance_id = #{appearanceId} " + "</if>" + 
		  			"</where>"+ 
			"</script>")
	int count(Map<String, Object> map);
	
	@Insert("insert into tb_truck (`truck_name`, `truck_temp`, `truck_type`, `driver`, `telephone`, `truck_number`, `package_time`, `truck_start`, `truck_end`, `flag`, `operator_id`, `appearance_id`)"
	+ "values (#{truckName}, #{truckTemp}, #{truckType}, #{driver}, #{telephone}, #{truckNumber}, #{packageTime}, #{truckStart}, #{truckEnd}, #{flag}, #{operatorId}, #{appearanceId})")
	int save(TruckDO truck);
	
	@Update("<script>"+ 
			"update tb_truck " + 
					"<set>" + 
		            "<if test=\"truckId != null\">`truck_id` = #{truckId}, </if>" + 
                    "<if test=\"truckName != null\">`truck_name` = #{truckName}, </if>" + 
                    "<if test=\"truckTemp != null\">`truck_temp` = #{truckTemp}, </if>" + 
                    "<if test=\"truckType != null\">`truck_type` = #{truckType}, </if>" + 
                    "<if test=\"driver != null\">`driver` = #{driver}, </if>" + 
                    "<if test=\"telephone != null\">`telephone` = #{telephone}, </if>" + 
                    "<if test=\"truckNumber != null\">`truck_number` = #{truckNumber}, </if>" + 
                    "<if test=\"packageTime != null\">`package_time` = #{packageTime}, </if>" + 
                    "<if test=\"truckStart != null\">`truck_start` = #{truckStart}, </if>" + 
                    "<if test=\"truckEnd != null\">`truck_end` = #{truckEnd}, </if>" + 
                    "<if test=\"flag != null\">`flag` = #{flag}, </if>" + 
                    "<if test=\"operatorId != null\">`operator_id` = #{operatorId}, </if>" + 
                    "<if test=\"appearanceId != null\">`appearance_id` = #{appearanceId}, </if>" + 
          					"</set>" + 
					"where truck_id = #{truckId}"+
			"</script>")
	int update(TruckDO truck);
	
	@Delete("delete from tb_truck where truck_id =#{truckId}")
	int remove(Integer truck_id);
	
	@Delete("<script>"+ 
			"delete from tb_truck where truck_id in " + 
					"<foreach item=\"truckId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + 
						"#{truckId}" + 
					"</foreach>"+
			"</script>")
	int batchRemove(Integer[] truckIds);
}
